Just a question is it possible to combine the fritzing and code of a temperature sensor to a pushbutton? I’m basically making a claw that is opened by the spinning of a motor, the motor is spun by the sensor but I also want it to reverse? here’s the code and the frtizings
//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
//create 3 global variables
//PWM controls speed
//DIR A and B are the direction logic pins
int PWM = 3;
int DIRA = 4;
int DIRB = 5;
//create a global boolean variable to toggle
//when button is pressed, set it to true.
boolean state = true;
void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
//pinModes for H-Bridge control pins
pinMode(PWM,OUTPUT);
pinMode(DIRA,OUTPUT);
pinMode(DIRB,OUTPUT);
//set pin 6 to INPUT_PULLUP, no need for a pullup resistor
pinMode(6,INPUT_PULLUP);
}
void loop(){ // run over and over again
//create a local varaible thats stores the button state (1 or 0)
int buttonState = digitalRead(6);
//if buttonState is 0 (less than 1) toggle the state variable to
//the opposite of the current state (!state)
if(buttonState < 1){
state = !state;
delay(250);
//if state is false drive motor forward, else stop.
if(state == false){
int forward(250);
}
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0;
voltage != 1024.0;
// print out the voltage
Serial.print(voltage); Serial.println(" volts");
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
Serial.print(temperatureC); Serial.println(" degrees C");
if(temperatureC > 24){
analogWrite(9, 250);
}
else(temperatureC < 24);{
analogWrite(9,0);
delay(1000); //waiting a second
}
//custom function for forward
void forward(int Speed);{
digitalWrite(DIRA,250);
digitalWrite(DIRB,0);
}
//custom function for reverse
void reverse(int Speed);{
digitalWrite(DIRA,0);
digitalWrite(DIRB,250);
}
}
}