Hello Everyone,
I am new to Arduino, but before I begin, I would like to say a hearty THANK YOU to everyone who put these boards together. I have an interesting application where an Arduino will control the inverter drive on a small warper that I am developing. In the midst of building a component of the schematic I noticed something strange with my Arduino Leonardo. I am using a Fairchild HCPL3700 to sense voltage and input logic on pin#4. My code differs a only a little from the basic button example...
const int buttonPin = 4; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
The way it works is that when voltage is present, the LED turns off. At all other times it is ON. My connections are as follows.
| Arduino Pin | HCPL3700 Pin |
|---|---|
| 5V | 2 & 8 |
| GND | 5 & 3 (To turn the LED off) |
| Digital 4 | 6 |
Additionally, I have a 0.1uF capacitor connected to pins 8 & 5 of the HCPL3700 in accordance with the datasheet here.
When I test it with the USB cable hooked up, it is very buggy and won't display proper logic. However, when I unplug the USB and plug in my Adafruit 9v power supply, everything works fine. I have tried it on multiple computers with no change. Any ideas why this is happening?