#include const byte rxPin = 2; const byte txPin = 3; const byte ENAPin = 11; const byte IN1Pin = 10; const byte IN2Pin = 9; const byte LM35Pin = A0; SoftwareSerial mySerial(rxPin, txPin); unsigned long lastReading = 0; boolean fw = true; void setup() { mySerial.begin(9600); analogReference(INTERNAL); pinMode(IN1Pin, OUTPUT); pinMode(IN2Pin, OUTPUT); digitalWrite(IN1Pin, HIGH); digitalWrite(IN2Pin, LOW); analogWrite(ENAPin, 0); } void loop() { byte motorSpeed = 0; float temperature; byte command; if (millis() - lastReading >= 1000) { lastReading = millis(); temperature = (analogRead(LM35Pin) * 1.1 * 100 / 1024); mySerial.println(temperature); } if (mySerial.available() > 0) { command = mySerial.read(); if (command == 1) { while(mySerial.available()==0); motorSpeed = mySerial.read(); analogWrite(ENAPin, motorSpeed); } else if (command == 2) { reverse(); } } } void reverse() { if (fw) { digitalWrite(IN1Pin, LOW); digitalWrite(IN2Pin, HIGH); } else { digitalWrite(IN2Pin, LOW); digitalWrite(IN1Pin, HIGH); } fw = !fw; }