Sensor input not normal

Hi i need this as soon as possible, i am working with a tilt sensor, it is digital, i hope it is not burn, but i see ther's not need of resistor for it, it gives me feedback like "1111100000000000000111111000000000000011111100000000000000" when it should be just "1111...", do you know how that can be possible?
Thankyou!!

(deleted)

You are right i just had to go very fastly, sorry.
#include "FastLED.h"

#define NUM_LEDS 56

//per striscia led
#define DATA_PIN 6

//parte per tilt
const int buttonPin = 8;
int buttonState = 0;

// Define the array of leds
CRGB leds[NUM_LEDS];
int NumeroWhite = 0;
int NumeroBlack = 0;

void setup() {

Serial.begin(9600);
delay(2000);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
pinMode(buttonPin, INPUT);
LEDS.setBrightness(10);

}

void loop() {
buttonState = digitalRead(buttonPin);
Serial.print(buttonState);
//delay(10);
/*if (buttonState == HIGH) {

NumeroBlack = 0;
while(NumeroWhite < NUM_LEDS){
leds[NumeroWhite] = CRGB::Gray;
FastLED.show();
NumeroWhite++;
// delay(2000);
}
}
else{

NumeroWhite = 0;
while(NumeroBlack < NUM_LEDS){
leds[NumeroBlack] = CRGB::Black;
FastLED.show();
NumeroBlack++;
}

} */
}

I don't see anything in that code about any tilt sensor and I don't see anything that would give an output in 1's and 0's like the one you describe.

You're going to have to slow down for just a second and think. You need to describe this whole project and situation to someone who hasn't been there with you and has never seen it before. You need to be specific about what it is, what it is supposed to do, and what it is doing or not doing that isn't up to expectations. If you want help, especially fast help, then you need to put some thought into helping people help you.

      pinMode(buttonPin, INPUT);
  buttonState = digitalRead(buttonPin);
  Serial.print(buttonState);

Has the input pin got a resistor holding it either HIGH or LOW at all times when not "pressed" or is it floating at an unknown voltage until pressed ?

(deleted)

Ok, before i have to learn the language of this forum (or forum in general) i thought i could write as much as i want but there a limit in the time, so i will write in a single message, anyway i don't know how to do the window for the code space...

#include "FastLED.h"

#define NUM_LEDS 56

//per striscia led
#define DATA_PIN 6

//parte per tilt
const int buttonPin = 8;
int buttonState = 0;

// Define the array of leds
CRGB leds[NUM_LEDS];
int NumeroWhite = 0;
int NumeroBlack = 0;

void setup() {

Serial.begin(9600);
delay(2000);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
pinMode(buttonPin, INPUT);
LEDS.setBrightness(10);

}

void loop() {
buttonState = digitalRead(buttonPin);
Serial.print(buttonState);
//delay(10);
/*if (buttonState == HIGH) {

NumeroBlack = 0;
while(NumeroWhite < NUM_LEDS){
leds[NumeroWhite] = CRGB::Gray;
FastLED.show();
NumeroWhite++;
// delay(2000);
}
}
else{

NumeroWhite = 0;
while(NumeroBlack < NUM_LEDS){
leds[NumeroBlack] = CRGB::Black;
FastLED.show();
NumeroBlack++;
}

} */
}

This is the code i made a part as a code cause it is not about the tilt, i called "button" the tilt cause it works like a button and i started my code by the example "button".
In general this code should turn on a led stip when it is HIGH.
I'm quite sure the diagram is right cause very simple just 5 wires, but yes, i didn't use resistor maybe i killed my arduino? it works on 5 volts.

this is where i bought arduino and tilt.
I hope i wrote everything

(deleted)

banshee119:
anyway i don't know how to do the window for the code space...

Because you decided to skip reading the instructions. Very likely, this is at the heart of your coding problem as well. Reading the documentation is a habit you should get into if you want to get very far in the coding world.

How to use this forum - please read
You can obviously skip the bits on creating an account.

Can you show the wiring? How do you have your button (or is it a tilt sensor ((seriously how the hell am I supposed to help you if you're not telling me what exactly you have?)))

How do you have you button wired? You're not using the internal pull-up resistor on the input, do you have an external one? Do you have a floating input issue? (there's something to google if you don't know what it means.)

OK i read the manual:
Hi i'm Simone, my circuit is composed by a tilt sensor, a 220 hom resistor and an arduino one, all found inside the starter kit that you find in this link:

#include "FastLED.h"

#define NUM_LEDS 56

//per striscia led
#define DATA_PIN 6

//parte per tilt 
const int buttonPin = 12;   
int buttonState = 0;

// Define the array of leds
CRGB leds[NUM_LEDS];
int NumeroWhite = 0;
int NumeroBlack = 0;



void setup() { 
  
      Serial.begin(9600);
      delay(2000);
  	  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
      pinMode(buttonPin, INPUT);
      LEDS.setBrightness(10);
      

}

void loop() { 
  buttonState = digitalRead(buttonPin);
  Serial.print(buttonState);
  //delay(10);

}

This code has some particular features about the led strip libraries, but that is not important now, my problem is just the output i get from my tilt sensor, cause when it should be high it gives me a combination of "0" and "1", while i expect just a series of "1".
that is the part where i ask to the program a feedback:

buttonState = digitalRead(buttonPin);
  Serial.print(buttonState);

attached you find the wiring.
I think i was good this time, thank you!

Ahh...

A quick look at your wiring daigram shows a couple of problems.

First of all you have defined buttonPin as 12 but the diagram shows the tilt switch connected to pin 8. Which pin are you using 8 or 12?

Secondly if you are using the circuit shown you need a pull-up resistor. Currently when the switch is open there is nothing connected to the other end of the 220 ohm resistor connected to pin 8/12 of the arduino. This means that it picks up any stray voltages/rf fields and gives you the results you are seeing.

if you change your pinmode statement from this:-

pinMode(buttonPin, INPUT);

To this:-

pinMode(buttonPin, INPUT_PULLUP);

You will enable the arduino's internal pull-up resistor and everything should work as expected once you have changed the wiring to match the sketch or the sketch to match the wiring.

Ian

thanks Ian, in the meantime I have solved thanks to an image that proposed just my case, I think this is a particular kind of tilt, the diagram is in this link:

Despite this I must say that if your method were to work I would raise the problem of that triple contact that forced me to use the breadboard for convenience.
Regarding the pins yes, you are right, I got confused because in the various attempts I changed the entry and then remained that way.
Thank you very much, I will do some tests later;)