Arduino Programmes
Configuration 1 - direct analog voltage output
Configuration 2 - output 0V/5V and be connected to an external voltage divider to obtain +/- 1.5V
#include <IRremote.h> // Uses the IRremote library
int ReceiverPin = 2;
int LeftActuatorPin = 6;
int CounterElectrodePin = 10;
int RightActuatorPin = 9;
int ForwardState = 0;
int LeftState = 0;
int RightState = 0;
int OffState = 0;
IRrecv IRreceive(ReceiverPin);
decode_results results;
void setup() {
Serial.begin(9600); // "begin" is a function in the "Serial library"
Serial.println("IR signals received");
IRreceive.enableIRIn();
pinMode(LeftActuatorPin, OUTPUT);
pinMode(CounterElectrodePin, OUTPUT);
pinMode(RightActuatorPin, OUTPUT);
}
void loop() {
if(IRreceive.decode(&results)){ // When the receiver decodes a signal
Serial.println(results.value); // To show the results on the serial monitor on the computer
IRreceive.resume(); // resume should be placed here
if((results.value == 868255232)||(results.value ==3017984774)){
// "Power" on the SONY TV control OR "Power" on the Universal TV switch
ForwardState = 1;
LeftState = 0;
RightState = 0;
OffState = 0;
}
if(results.value == 719156785){ // "INFO" in the SONY TV switch
ForwardState = 0;
LeftState = 1;
RightState = 0;
OffState = 0;
}
if(results.value == 656){ // "Mute" in the SONY TV switch
ForwardState = 0;
LeftState = 0;
RightState = 1;
OffState = 0;
}
if((results.value == 2542703151)||(results.value == 3687369586)){
// "Exit" on the SONY TV control OR "1" on the Universal TV switch
ForwardState = 0;
LeftState = 0;
RightState = 0;
OffState = 1;
}
}
if(ForwardState == 1){
analogWrite(LeftActuatorPin, 224);
// The voltage output at this pin would be Vcc*(224/255).
// So for 5V Vcc, the output would be around 4.4V
analogWrite(CounterElectrodePin, 112);
analogWrite(RightActuatorPin, 224);
delay(4000);
analogWrite(LeftActuatorPin, 0);
analogWrite(CounterElectrodePin, 112);
analogWrite(RightActuatorPin, 0);
delay(3000);
}
if(LeftState == 1){
analogWrite(LeftActuatorPin, 224);
analogWrite(CounterElectrodePin, 112);
analogWrite(RightActuatorPin, 0);
delay(4000);
analogWrite(LeftActuatorPin, 0);
analogWrite(CounterElectrodePin, 112);
analogWrite(RightActuatorPin, 0);
delay(3000);
}
if(RightState == 1){
analogWrite(LeftActuatorPin, 0);
analogWrite(CounterElectrodePin, 112);
analogWrite(RightActuatorPin, 224);
delay(4000);
analogWrite(LeftActuatorPin, 0);
analogWrite(CounterElectrodePin, 112);
analogWrite(RightActuatorPin, 0);
delay(3000);
}
if(OffState == 1){
digitalWrite(LeftActuatorPin, LOW);
digitalWrite(CounterElectrodePin, LOW);
digitalWrite(RightActuatorPin, LOW);
}
}
#include <IRremote.h> // Uses the IRremote library
int ReceiverPin = 2;
int LeftActuatorPin = 8;
int CounterElectrodePin = 9;
int RightActuatorPin = 10;
int ForwardState = 0;
int LeftState = 0;
int RightState = 0;
int OffState = 0;
IRrecv IRreceive(ReceiverPin);
decode_results results;
void setup() {
Serial.begin(9600); // "begin" is a function in the "Serial library"
Serial.println("IR signals received");
IRreceive.enableIRIn();
pinMode(LeftActuatorPin, OUTPUT); // initialize digital pin 8 as an output
pinMode(CounterElectrodePin, OUTPUT); // initialize digital pin 11 as an output
pinMode(RightActuatorPin, OUTPUT); // initialize digital pin 12 as an output
}
// the loop function runs over and over again forever
void loop() {
if(IRreceive.decode(&results)){ // When the receiver decodes a signal
Serial.println(results.value); // To show the results on the serial monitor on the computer
IRreceive.resume(); // resume should be placed here
if(results.value == 868255232){ // "Power" on the SONY TV control
ForwardState = 1;
LeftState = 0;
RightState = 0;
OffState = 0;
}
if(results.value == 719156785){ // "INFO" in the SONY TV switch
ForwardState = 0;
LeftState = 1;
RightState = 0;
OffState = 0;
}
if(results.value == 656){ // "Mute" in the SONY TV switch
ForwardState = 0;
LeftState = 0;
RightState = 1;
OffState = 0;
}
if(results.value == 2542703151){ // "Exit" on the SONY TV control
ForwardState = 0;
LeftState = 0;
RightState = 0;
OffState = 1;
}
}
if(ForwardState == 1){
digitalWrite(LeftActuatorPin, HIGH);
// point A (the positive electrode of the left actuator) is 5*(2/3)=3.333V
digitalWrite(CounterElectrodePin, HIGH);
// point CE is 5*(1/3)=1.667V
digitalWrite(RightActuatorPin, HIGH);
// point B (the positive electrode of the right actuator) is 5*(2/3)=3.333V
delay(4000); // wait for 4 seconds: in these 4s, bend
digitalWrite(LeftActuatorPin, LOW); // point A =0V
digitalWrite(CounterElectrodePin, HIGH); // point CE is 1.667V
digitalWrite(RightActuatorPin, LOW); // point B is 0V
delay(3000); // wait for 3 second: in these 3s, unbend
}
if(LeftState == 1){
digitalWrite(LeftActuatorPin, HIGH);
// point A (the positive electrode of the left actuator) is 5*(2/3)=3.333V
digitalWrite(CounterElectrodePin, HIGH); // point CE is 5*(1/3)=1.667V
digitalWrite(RightActuatorPin, LOW);
// point B (the positive electrode of the right actuator) is 0V
delay(4000); // wait for 4 seconds: in these 4s, bend
digitalWrite(LeftActuatorPin, LOW); // point A =0V
digitalWrite(CounterElectrodePin, HIGH); // point CE is 1.667V
digitalWrite(RightActuatorPin, LOW); // point B is 0V
delay(3000); // wait for 3 second: in these 3s, unbend
}
if(RightState == 1){
digitalWrite(LeftActuatorPin, LOW);
// point A (the positive electrode of the left actuator) is 0V
digitalWrite(CounterElectrodePin, HIGH); // point CE is 5*(1/3)=1.667V
digitalWrite(RightActuatorPin, HIGH);
// point B (the positive electrode of the right actuator) is 5*(2/3)=3.333V
delay(4000); // wait for 4 seconds: in these 4s, bend
digitalWrite(LeftActuatorPin, LOW); // point A =0V
digitalWrite(CounterElectrodePin, HIGH); // point CE is 1.667V
digitalWrite(RightActuatorPin, LOW); // point B is 0V
delay(3000); // wait for 3 second: in these 3s, unbend
}
if(OffState == 1){
digitalWrite(LeftActuatorPin, LOW); // point A =0V
digitalWrite(CounterElectrodePin, LOW); // point CE is 0V
digitalWrite(RightActuatorPin, LOW); // point B is 0V
}
}