Here is my program, I want to:
1 The microcontroller, Arduino UNO R3 sends 3.3V to the sensor, Accelerometer, MMA7361 got from http://www.kynix.com/Search/MMA7361.html
2 The sensor turns on and send signal to the microcontroller.
3 When I move the sensor and if the voltage becomes more than 2V, the microcontroller sends 1.5V to the Transistor. Otherwise send 0V.
int outputPin1 = 3; // Pin D3
int outputPin2 = 5; // Pin D5
int analogPin = 0; // Input Pin A0
void setup()
{
pinMode (outputPin1, OUTPUT);
pinMode (outputPin2, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int volts = 170; // send signals of 3.3v
analogWrite(outputPin1, volts); // to Accelerometer
int reading = analogRead(analogPin); // receive signal
delay(1000); // delay 5sec.
if (volts >= 100) // Input voltage is more than 2.0V
{
int volts = 77; // send signals of 1.5V
analogWrite(outputPin2, volts); // to Transistor
}
else
{
int volts = 0;
analogWrite(outputPin2, volts); // to Transistor
}
}
When I measure with Digital Multi Meter, it keeps showing 1.5V even it doesn’t change the position of the sensor.
I guess there’s some problem in the if, else line.