Hello everyone. I connected my led to a pwm pin so that I could regulate its brightness thanks to a slider in my mit app. However, the trick only works when I move the slider to the position, and then it starts dropping by 1 each second, till reaching -1 (I serial.println the variable so that I could see it) I'm just going to paste everything here. The led part is at the bottom, of both arduino and mit blocks
The blocks I disabled weren't part of the program I've had an issue with, I had used them because I wanted to see something but the error was still there. I initially wanted the app to send arduino values in both the button event and the slider position changing, but I noticed that it's not as efficient, because the phone told me that the app stopped working. Is there any other way I could be able to have both the button and the slider send data to arduino or should I rely only on one of these? And also, besides those disabled blocks that I didn't use, the slider thumb position block is correct? And finally, how can I keep that one value I send from the phone stable in arduino? It's as if when I send a "40" value, for example, it goes up to that value only for an instant, and then it drops right after. Sorry for the many questions
Use only one clock to read temperature and humidity. After reading, split the data into "|", enter the first item from the list into the temperature label, and the second one into the humidity label.
I assume your slider is set to the maximum value of 100. So why are you sending data as 4 bytes? Send as one byte.
You can use the slider extension to send data only when you lift your finger off the slider. Your arduino code has a latency of 2s, so the led will not respond very quickly.
You should rewrite the arduino code so that arduino sends data to android every 2s, while android data should be read without delay. Read about the multitasking and milis function in arduino.
Hello, I've changed the code according to what you said (I also made the clock timers 20% faster because the phone would crash otherwise), and now it works a lot better, it's more responsive. However, I still have one major problem: when I set the slider to a certain value, the led will assume that brightness only till the next Serial.read(), and then it drops again to -2 (that is an odd value, why's that?). Could the slider extension I've yet to download solve this? Or is it another error in the code?
As you can see here, I've entered the value "52" from the phone (which of course turned to 132 thanks to map function), but then the value goes back to -2
About the extension, how should I even download it? I tried putting the url but mit app tells me that the uploaded file does not contain any component definition files
Hello. I want to regulate several leds by sending data from my phone to arduino and, in order to specify to arduino on which led I want to control, I've thought of creating a new variable (in both the app and on arduino) I would assign a different value for each selected item from the spinner and then I would send it to arduino. Then, thanks to the switch function, arduino would be able to distinguish which led to power up, but apparently that's not the case. Here, I will leave both arduino and app sketches.
I didn't know how the forum worked, I thought that after some time I wasn't gonna be able to reply to the other thread anymore. But it's fine, sorry for the mess
I don't totally get what you're doing, but I'm just going to describe how I would do it.
Maybe that helps.
First:
Make the android app that has output like that: a | 45
The letter ist the led we want to control the number is the brightness.
I think you know how to get both pieces of information with app inventor and there is a tool to merge them with a | .
Then I'd sent this to the Arduino. (And only send a new code over Bluetooth if the user has changed the input)
Second:
Make the Arduino read the serial Bluetooth if available.
Then it reads the received code in. There s a simple code to divide between the | .
Now you got two variables, one for the led, and one for brightness.
Now you just need two lines of code to set the led and the brightness.
I hope I was able to help you a bit.
If not feel free to ask again and I'll try to help furthermore.
Oh okay, you got it right, by the way. However, I don't really know how to divide the values in arduino. I've tried googling it but every code uses different functions and that confuses me even more. Do you have any tips on how to write this for the program?
Oh great, now that I know the problem I'm sure we can find a solution.
Yeah, I've done it before and should be able to provide a sample code for the Arduino.
I just have to search for it on my harddrive. Gonnna do this in the evening and then send it to you.
//READ THE STRING TO THE FIRST "|" DIVIDER AND STORE AS A VARIABLE
String myDate = Serial.readStringUntil('|');
Serial.read();
//STORE THE NEXT SECTION OF STRING AS A VARIABLE
String myTime = Serial.readStringUntil('\n');
Serial.read();
That's the code I have used to dive strings on the Arduino.
If you need any further help, just let me know.
Hello. First of all thank you for the help on that, now it works just fine! Now, though, I've got another issue: I will try to explain it here.
I had made my dht11 sensor send temperature and humidity data to my phone and display it on my phone, and that works. However, I also want to set a value like a temp_max, which in case it gets reached, my arduino will trigger the red led on and off (like an alarm, but that's not the problem here). The actual problem is that whenever I set this max value more than once (sometimes twice), a mit app inventor error gets displayed. Since it had displayed either once or twice, I strongly believe that it's got something to do with clock from mit and the measurement time from arduino. I will send both the sketches and also the error that gets displayed.