Arduino To read

Okay, so here is my issue. Not sure where to place this in categories.

I have made a lighting detection module from an arduino. (I will place code at the end). I fot all the information from this web site. It reads out to a serial monitor.

So here is my problem. I can get it to read once or maybe twice. but I keep getting aio errors. There so bad that it crashes home assistant. I remove arduino serial and it starts working again. Is there something special I need to do? I would really like for this to work. If the internet goes out. I can still know if the lighting is close and I can have the software that the correct actions. Is there something I need to change in this code?


#define FASTADC 1

// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

int data = 512;
int storage[512];

long batchStarted;
long batchEnded;
int reading;
int count;
int maximum;
int minimum;
bool toSend;

void setup() {
 // set prescale to 16
 sbi(ADCSRA,ADPS2) ;
 cbi(ADCSRA,ADPS1) ;
 cbi(ADCSRA,ADPS0) ;
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly:
  reading = (analogRead(A4));
  if ((!toSend)&&(count!=0)&&((reading>storage[count-1]+10)||(reading<storage[count-1]-10))){
  if ((count == 512) && (toSend))
    batchEnded = millis();
    batchStarted = millis();
  else if (count==512){
    batchEnded = millis();
    batchStarted = millis();


void sendData()
  for (int i=0;i<data;i++){

How are you connecting the arduino device to home assistant?

The code it might be better readable if putted on the code tag. See </> above the editor…

USB cable connected straight to the raspberry pi.

But what integration are you using?

This is the directions i followed.

I am no expert in arduino programming, but your sketch in post one seems to be sending the data out the serial port. That is not how the home assistant - arduino integration works, as can be seen in the page you referred to.

It shows the serial port information. That is the weird thing. But after it reads twice. It crashes.

I need it as a sensor. I want to be able to read the serial data and i make an automation with it. I need it to control 8 relay’s. I messed with wwlln but it doesnt provide any numbers for automations.

I tried this also.

With no glory.

Shows the serial port information where? Not in home assistant I’ll bet,

It is on the Arduno serial port. I think that it might be to high baudrate.

I know it is on the serial port, but that is not how the arduino integration works. Have you even read this?

According OP intent I guess that he wants to read analog data from the pin A4. For such condition it would take a small python program to decipher the incoming data and transform it into serial data.

The serial sensor states that the baudrate is 9600, which is not what the arduthing program uses. Further more it’s necessary to understand at which rate the data are acquired.