Light sensors and Phillips hue - arduino

I am designing a system where a light sensor detects light in a room and based on that it adjusts the output of a few light bulbs. The goal is to maintain a standard level of light in the room based on the environmental conditions such as external sunlight. The code is written in Python and uses Phillips hue bulbs to function. The pseudocode is as follows:
if (read light is in between 10 - 50 lumins) {
set bulb to 100 lumins
}
if (read light is in between 51-100 lumins) {
set bulb to 50 lumins
}
etc
However what ends up happening is that after each iteration, when the light is set to the specific value, the sensor detects the bulbs' own light and on the next iteration turns down the light. The lights end up flickering from high to low every second. Does anyone have any experience with this sort of thing, of an algorithm to deal with it? Essentially, the problem is that the light sensor is detecting the bulbs' own light and then undoing its previous decision. I am using a standard TSL2561 sensor to detect the light and the bulbs are Phillips hue.

The placement of the sensor is key in these situations. You can also try an optical filter but that is not the full solution.
Your algorithm is to crude to compensate for a dynamic environment. The real solution is to use a PID algorithm to make small adjustments over time to the light output to stay close to an ideal total (ambient+LED) light level.
See this example, there is many similar out there if you search for pid controller light sensor.
A simplified pseudo code representation for a PID like control system would be:
read in_lumins
if (in_lumins is in between 10 - 50 lumins) {
increment out_lumins
}
if (in_lumins is in between 51-100 lumins) {
decrement out_lumins
}
set bulb to out_lumins
Loop and repeat. Time increments on loop and/or increment size should vary with distance from ideal.

Related

i want to make home automation using enterance door autoamte light on off

I want to make home automation system for my final year project. One module of my project is light ON OFF on entrance, for that purpose I used IR sensor but the range of IR sensor is 20cm which is not suitable for my project, i need minimum 4 feet ranger to detect the human to turn ON OFF light. anyone suggest me to which sensor is best for that.
Thanks
You csn use what's called human sensor, it is very sensitive and provide the on off signal you need, low cost, easy to use ans small enough to fit inside any sensor enclosure.

How to make a pulse sensor Waterproof ? Or is there any waterproof pulse sensor?

Hi there this might sound stupid but please help me . Does anyone know how to make a pulse sensor a waterproof and water resistant one ?
If you're referring to heartrate sensors like those on pulsesensor.org, the simple answer is no.
There are two issues here. The first is whether the circuit could be fully waterproofed - the answer to this is yes. The second is harder, however - which is whether the sensor you refer to would be effective under water.
These sensors use a green light to detect changes in bloodflow, and they work poorly underwater even in commercial sensors. They are very sensitive to being jostled by water, and lose accuracy when there is water between the sensor and the skin.
There's a useful in-depth discussion of this here:
https://www.yourswimlog.com/best-waterproof-heart-rate-monitors-for-swimming/
If you need to measure heartrate underwater, you might have better luck with a chest strap sensor. These work by sensing elongation of a strap wrapped around the chest, and calculate heartrate based on those changes. Commercial versions are readily available and work well.
If all you're worried about is waterproofing the circuit for shallow water, this can be accomplished pretty easily. All elements would need to be encased in fully waterproof material. You could simply slip the whole thing in a waterproof baggie (google 'dry sleeve' or 'acquapac), or if you're up to it, build a silicon mold to encase the project.

Arduino HC-SR04 water experiment

I am working on an experiment with the HC-SR04 sound sensor, and i am using it to record the speed of sound. I successfully measured the speed of sound in air, but when measuring it in water, I encountered a small problem. The sound waves emitted by the sensor are both absorbed and reflected off the water. Obviously, the reflected sound waves are the first ones to reach the sensor, and therefore are the ones used for calculating the speed of sound. Is there a way to code the Arduino program in order to ignore the first set of waves and only record the set of waves that were absorbed by the water? I was thinking of increasing the delay time for the pulse, but I'm not sure that would work.
This answer is theorical only. No test has been done yet.
By adding a small delay, such as 1 - 2 milliseconds could work.
You could calculate the distances twice and get the result from the seconds calculations only.
For you info, here is the speed of sound in water : 1,484 m/s.

Arduino + multiple ultrasonic sensors + interference

I have two buggies moving around a track, both of which use ultrasonic measurement modules to detect obstacles in their paths and are controlled by Arduino microcontrollers. The two ultrasonic sensors operate at the same frequency and this frequency cannot be changed. The two ultrasonic sensors are interfering with each other. How can I reduce this interference, or prevent it, by adding something to the Arduino code. The hardware cannot be changed. Thanks for your help
There are in general six ways to reduce interference between two channels (see for example http://en.wikipedia.org/wiki/Multiplexing) - two of which don't apply to sound. That leaves you with four:
space - don't operate in the same space (e.g. cell towers): not applicable for you
frequency - (e.g. channels) you said you can't change that
time - don't operate at the same time
code - send out different amplitude patterns
In a sense, "code" is a bit like "time", but more complicated. With "time", you try to time it so the two transducers don't transmit at the same time. With "code", they send complex pulse sequences and use these to eliminate the interference.
I think your best bet (simple, but effective) is "time". This is going to depend a little bit on the frequency of update that you need, but you could make one buggy the "master", sending a short chirp every 100 ms (say); then have the second buggy wait until it hears the master chirp, and send its own pulse 50 ms later (when it knows the other buggy will be quiet). In this way each will have 10 updates per second, but they will not interfere.
To be more robust, the "slave" buggy could decide (after not hearing a pulse from the "master") to send its own pulse after 100 ms - this way it can operate when there is only one buggy present. And they could in fact each use this algorithm - then there is no "master" and "slave" and they have the same code (usually a good idea). As a final tweak, if you make this "wait for n ms" interval random, you will have implemented a version of "carrier sense multiple access with collision detection" - see http://en.wikipedia.org/wiki/Carrier_sense_multiple_access_with_collision_detection
Good luck.

How to fade out volume naturally?

I have experimented with a sigmoid and logarithmic fade out for volume over a period of about half a second to cushion pause and stop and prevent popping noises in my music applications.
However neither of these sound "natural". And by this I mean, they sound botched. Like an amateur engineer was in charge of the sound decks.
I know the ear is logarithmic when it comes to volumes, or at least, twice as much power does not mean twice as loud. Is there a magic formula for volume fading? Thanks.
I spent many of my younger years mixing music recordings, live concerts and being a DJ for my school's radio station and the one thing I can tell you is that where you fade is also important.
Fading in on an intro or out during the end of a song sounds pretty natural as long as there are no vocals, but some of these computerized radio stations will fade ANYWHERE in a song to make the next commercial break ... I don't think there's a way to make that sound good.
In any case, I'll also answer the question you asked ... the logarithmic attenuation used for adjusting audio levels is generally referred to as "audio taper". Here's an excellent article that describes the physiology of human hearing in relation to the electronics we now use for our entertainment. See: http://tangentsoft.net/audio/atten.html.
You'll want to make sure that the end of the fade out is at a "zero crossing" in the waveform.
Half a second is pretty fast. You might just want to extend the amount of time, unless it must be that fast. Generally 2 or 3 seconds is more natural.
More on timing, it should really be with the beat rate of the music, and end at a natural point in the rhythm. Try getting the BPM of the song (this can be calculated roughly), and fading out over an interval equal to a whole or half note in that timing.
You might also try slowing down the playback speed while you're fading out. This will give a more natural vinyl record or magnetic tape sounding stop/pause. Linearly reduce playback speed while logarithmically reducing volume over the period of 1 second.
If you're just looking to get a clean sound sound when pausing or stopping playback then there's no need to fade at all - just find a zero-crossing point and stop there (or more realistically just fill the rest of that final buffer with silence). Fading out when the user expects the sound to stop immediately will sound unnatural, as you've noticed, because the result is decoupled from the action.
The reason for stopping at a zero-crossing point is that zero is the steady state value while the audio is stopped, so the transition between the two states is seamless. If you stop playback when the last sample's amplitude is large then you are effectively introducing transients into the audio from the point of view of the audio hardware when it reconstructs the analogue signal, which will be audible as pops and/or clicks.
Another approach is to fade to zero very fast (~< 10mS), which effectively achieves the same thing as the zero-crossing technique.

Resources