Problem reading pin state

Grove is a modulated, ready-to-use tool set.
Much like Lego, it takes a building block approach to assembling electronics.

Moderators: lily.li, violet, jeremy882, crail.lyu969

Post Reply
asptamer
Pre-kindergarten
Pre-kindergarten
Posts: 2
Joined: Mon May 16, 2016 12:52 am

Problem reading pin state

Post by asptamer » Mon May 16, 2016 1:01 am

Hello.

I'm trying to see if I can use the pins on the Grove to run external circuits, like push buttons and toggle switches that do not connect directly to one of the 4-pin Grove ports. Specifically, I'm trying to use the side row digital pins to detect the state of a switch and then do something, in this example - change the color of an LED (which is connected to a grove port).

I'm trying to replicate this schematic:
orinsss.jpg
This is my setup:
20160515_124531.jpg
Here's the code:

Code: Select all

#include <ChainableLED.h>
#define NUM_LEDS 1
ChainableLED leds(6, 7, NUM_LEDS);

void setup() {
  pinMode(2, INPUT);
}

void loop() {
  int p=digitalRead(2);  
  if(p==HIGH){
    leds.setColorRGB(0,0,255,0);
  }
  else{
    leds.setColorRGB(0,255,0,0);
  }
    
  delay(100);
}
I've tried using 220ohm 440ohm, 1000ohm resistors. If I connect the setup to the ground as shown in the schematic, upon switch ON, the device shuts down - I'm guessing it's tripping the internal safeguard because the current is too high? If I don't use the ground, the pin state just doesn't get detected.

What am I missing? Why doesn't this work?

kavi
Staff
Staff
Posts: 305
Joined: Tue Dec 09, 2014 12:06 pm

Re: Problem reading pin state

Post by kavi » Tue May 17, 2016 6:41 pm

Hello,

Can you please modify your hardware connection as shown in the attached picture

Let us know the results.

Thanks and Regards

asptamer
Pre-kindergarten
Pre-kindergarten
Posts: 2
Joined: Mon May 16, 2016 12:52 am

Re: Problem reading pin state

Post by asptamer » Thu May 26, 2016 9:08 am

This worked! Thank you. Could you explain why the other way did not work?

Sorry for the delayed response, I had trouble logging in - in fact, still cannot login using Chrome. Finally tried with IE, and it let me get in...

kavi
Staff
Staff
Posts: 305
Joined: Tue Dec 09, 2014 12:06 pm

Re: Problem reading pin state

Post by kavi » Thu May 26, 2016 3:36 pm

Hi,

Thanks for letting us know it worked.

In your previous circuit you was actually trying to short the Vcc and GND using the switch so only your board got tripped.

Regards,
kavi

Post Reply